﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data;
using HumanManagement.DataAccess;
using HumanManagement.BusinessObjects;
using System.Web.UI;
using System.Web.UI.WebControls;


namespace BSC_HumanManagement.Code
{
    public class Staticvariable
    {
        public static string connectString = ConfigurationManager.ConnectionStrings["data"].ConnectionString;
        public static string PermissionName_View = "Xem";
        public static string PermissionName_Edit = "Sửa";
        public static string PermissionName_Add = "Thêm";
        public static string PermissionName_Delete = "Xóa";
        public static string PermissionName_Sync = "Đồng bộ";

        PersonalProfileDA objPersonalProfileDA = new PersonalProfileDA();
        ContractTypeDA objContractTypeDA = new ContractTypeDA();
        JobPositionDA objJobPositionDA = new JobPositionDA();
        MaritalStatusCategoryDA objMaritalStatusCategoryDA = new MaritalStatusCategoryDA();
        LeaderPositionDA objLeaderPositionDA = new LeaderPositionDA();
        OccupationDA objOccupationDA = new OccupationDA();
        ContactPhoneCategoryDA objContactPhoneCategoryDA = new ContactPhoneCategoryDA();
        ForeignLanguageDA objForeignLanguageDA = new ForeignLanguageDA();
        ForeignLanguageLevelDA objForeignLanguageLevelDA = new ForeignLanguageLevelDA();

        public void CheckPermission(UserControl _uc  )
        {
            string _session_username = Convert.ToString(_uc.Session["login_username"]);
            _uc.Session["permissionView"] = false;
            _uc.Session["permissionEdit"] = false;
            _uc.Session["permissionDelete"] = false;
            _uc.Session["permissionAddNew"] = false;
            IDataReader _objIDataReader = SqlHelper.ExecuteReader(Code.Staticvariable.connectString, CommandType.Text, "Select FunctionCategory, FunctionName, SubFunctionName " +
                "From v_UserFunction Where UserName = '" + Convert.ToString(_uc.Session["login_username"]) + "'");
            while (_objIDataReader.Read())
            {
                if (_objIDataReader["FunctionName"].ToString().Equals(_uc.Request.QueryString["FunctionName"]))
                {
                    switch (_objIDataReader["SubFunctionName"].ToString())
                    {
                        case "Xem":
                            _uc.Session["permissionView"] = true;
                            break;
                        case "Sửa":
                            _uc.Session["permissionEdit"] = true;
                            break;
                        case "Xóa":
                            _uc.Session["permissionDelete"] = true;
                            break;
                        case "Thêm":
                            _uc.Session["permissionAddNew"] = true;
                            break;
                        default:
                            break;
                    }
                }

            }
        }

        public string GetPersonalProfile_FullName_ByID(int _ID, int sessionIDPersonal)
        {
            PersonalProfile _objPersonalProfile = objPersonalProfileDA.GetByID(_ID, sessionIDPersonal);
            return _objPersonalProfile.FullName;
        }

        public string GetContractType_Name_ByID(int _ID)
        {
            ContractType _objContractType = objContractTypeDA.GetByID(_ID);
            return _objContractType.ContractType_Field;
        }

        public string GetMaritalType_Name_ByID(int _ID)
        {
            MaritalStatusCategory _objContractType = objMaritalStatusCategoryDA.GetByID(_ID);
            return _objContractType.MaritalStatusCategory_Field;
        }

        public string GetJobPosition_Name_ByID(int _ID)
        {
            JobPosition _objJobPosition = objJobPositionDA.GetByID(_ID);
            return _objJobPosition.JobPosition_Field;
        }

        public string GetLeaderPositionAppointment_Name_ByID(int _ID)
        {
            LeaderPosition objLeaderPosition = objLeaderPositionDA.GetByID(_ID);
            return objLeaderPosition.LeaderPositionName;
        }

        public string GetOccupation_Name_ByID(int _ID)
        {
            Occupation obj = objOccupationDA.GetByID(_ID);
            return obj.OccupationName;
        }

        public string GetContactPhoneType_Name_ByID(int _ID)
        {
            ContactPhoneCategory obj = objContactPhoneCategoryDA.GetByID(_ID);
            return obj.ContactPhoneCategory_Field;
        }

        public string GetForeignLanguage_Name_ByID(int _ID)
        {
            ForeignLanguage obj = objForeignLanguageDA.GetByID(_ID);
            return obj.ForeignLanguage_Field;
        }

        public string GetForeignLanguageLevel_Name_ByID(int _ID)
        {
            ForeignLanguageLevel obj = objForeignLanguageLevelDA.GetByID(_ID);
            return obj.ForeignLanguageLevel_Field;
        }
    }
}